import Vue from "vue";
import VueRouter from "vue-router";
import login from "../components/login/login.vue";
import store from "../store/store";

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err);
};
Vue.use(VueRouter);

if (sessionStorage.getItem('token')) {
    store.commit('set_token', sessionStorage.getItem('token'))
}

const router = new VueRouter({
    linkActiveClass: "active",
    routes: [
        {
            path: "/",
            name: login,
            meta: {
                title: "IMAGINE_WEB"
                /* keepAlive:true*/
            },
            component: resolve => require(['../components/login/login.vue'], resolve),
        },
        {
            path: "/login",
            redirect: {name: "login"}
        },
        {
            path: "/sharee",
            name: "sharee",
            meta: {
                title: "登录"
                /*keepAlive:true*/
            },
            component: resolve => require(['../components/mobile/sharee'], resolve),
        },
        {
            path: "/hkPrivacy",
            name: "hkPrivacy",
            meta: {
                title: "隐私协议"
                /*keepAlive:true*/
            },
            component: resolve => require(['../components/mobile/hkPrivacy'], resolve),
        },
        {
            path: "/appSuccess",
            name: "appSuccess",
            meta: {
                title: "操作成功"
                /*keepAlive:true*/
            },
            component: resolve => require(['../components/mobile/appSuccess'], resolve),
        },
        {
            path: "/success",
            name: "successs",
            meta: {
                title: "操作成功"
                /*keepAlive:true*/
            },
            component: resolve => require(['../components/mobile/success'], resolve),
        },

        {
            path: "/download",
            name: "download",
            meta: {
                title: "下载"
                /*keepAlive:true*/
            },
            component: resolve => require(['../components/mobile/download'], resolve),
        },

        {
            path: "/homePage",
            name: "homePage",
            component: resolve => require(['../components/homePage/homePage'], resolve),
            redirect: {name: "statistics"},
            children: [
                {
                    // 可视菜单页面
                    path: "/",
                    name: "statistics",
                    meta: {
                        title: "IMAGINE_WEB"
                    },
                    component: () => import("../view/homePageManagement/index.vue")

                }, {
                    path: "bran",
                    name: "brandManage",
                    meta: {
                        title: "IMAGINE_WEB"
                    },
                    component: resolve => require(['../components/brandManagement/brandManage.vue'], resolve),
                },
            ]
        }
    ]
});

export default router;
